package com.mass.core.utils;

import java.io.Serializable;

/**
 * Ajax返回对象. <p />
 *
 */
public class AjaxResponse implements Serializable {
    /**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	/**
     * 操作成功.
     */
    public final static String SUCCESS = "00000";

    /**
     * 操作失败.
     */
    public final static String ERROR = "99999";

    /**
     * 响应结果编码.
     *
     */
    private String code;

    /**
     * 响应结果消息.
     */
    private String msg;

    /**
     * 响应结果数据.
     */
    private Object data;
    /**
     * 行数
     */
    private Long count;

    /**
     * 页数
     */
    private Integer pageIndex;

    public AjaxResponse(String code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }
    public AjaxResponse(String code, String msg, Object data,Long count,Integer pageIndex) {
        this.code = SUCCESS;
        this.msg = msg;
        this.data = data;
        this.count = count;
        this.pageIndex = pageIndex;
    }
    
    public Long getCount() {
		return count;
	}

	public void setCount(Long count) {
		this.count = count;
	}

	public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
    
    public static AjaxResponse success(Object data) {
        return success("success", data);
    }

    public static AjaxResponse success(String message) {
        return success(message, null);
    }
    public static AjaxResponse success(String code,String msg, Object data) {
        return new AjaxResponse(code, msg, data);
    }

    public static AjaxResponse success(String message, Object data) {
        return new AjaxResponse(SUCCESS, message, data);
    }
    
    public static AjaxResponse success(String message, Object data, Long count,Integer pageIndex) {
        return new AjaxResponse(SUCCESS, message, data , count,pageIndex);
    }

    public static AjaxResponse error(String message) {
        return error(message, null);
    }
    public static AjaxResponse error(String code,String msg, Object data) {
        return new AjaxResponse(code, msg, data);
    }

    public static AjaxResponse error(String message, Object data) {
        return new AjaxResponse(ERROR, message, data);
    }

    public Integer getPageIndex() {
        return pageIndex;
    }

    public void setPageIndex(Integer pageIndex) {
        this.pageIndex = pageIndex;
    }
}
